public class SolutionLCP19 {
    public int minimumOperations(String leaves) {
        int[] f1=new int[leaves.length()];
        f1[0]=leaves.charAt(0)=='r'?0:1;
        for (int i=1;i<leaves.length();i++){
            f1[i]=f1[i-1];
            if (leaves.charAt(i)=='y'){
                f1[i]++;
            }
        }
        int[] f2=new int[leaves.length()];
        f2[1]=leaves.charAt(1)=='y'?f1[0]:f1[0]+1;
        for (int i=2;i<leaves.length();i++){
            f2[i]=Math.min(f2[i-1],f1[i-1]);
            if (leaves.charAt(i)=='r'){
                f2[i]++;
            }
        }
        int[] f3=new int[leaves.length()];
        f3[2]=leaves.charAt(2)=='r'?f2[1]:f2[1]+1;
        for (int i=3;i<leaves.length();i++){
            f3[i]=Math.min(f3[i-1],f2[i-1]);
            if (leaves.charAt(i)=='y'){
                f3[i]++;
            }
        }
        return f3[leaves.length()-1];
    }

    public static void main(String[] args) {
        System.out.println(new SolutionLCP19().minimumOperations("rrryyyrryyyrr"));
    }
}
